package com.webserver.test;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class T1 {
    String uri;
    private String requestURI;//保存uri中请求部分
    private String queryString;//保存uri中参数部分
    private Map<String,String> querymap = new HashMap<>();
    @Test
    public void Test(){
        uri=".\\Webapps\\myweb\\register.html?username=111aa&password=11aa&date=2021-04-06&age=11";
        parseUri();
    }
    private void parseUri(){
        if (uri.contains("?")){
            String[] u=uri.split("\\?");
            requestURI=u[0];
            queryString=u[1];
            String[] strings=uri.substring(uri.indexOf("?")+1,uri.length()-1).split("\\&");
            for (int i=0;i<strings.length;i++) {
                String[] s=strings[i].split("\\=");
                querymap.put(s[0],s[1]);

            }
        }
        String username = querymap.get("username");
        String password = querymap.get("password");
        String date = querymap.get("date");
        String age = querymap.get("age");
        if(username.matches("\\d+|\\w+")&&password.matches("\\d+|\\w+")&&age.matches("\\d+")){
            System.out.println("lll");
        }
    }
}
